﻿using System;
using System.Windows.Forms;

namespace Microsoft.WowAddonStudio.Project.OptionPages
{
    public partial class AddOnStudioGeneralOptionsControl : UserControl
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="AddOnStudioGeneralOptionsControl"/> class.
        /// </summary>
        public AddOnStudioGeneralOptionsControl()
        {
            InitializeComponent();
        }

        public string CustomDeploymentLocation
        {
            get
            {
                if (checkBoxCustomLocation.Checked)
                    return textBoxCustomDeploymentLocation.Text;

                return null;
            }
            set
            {
                textBoxCustomDeploymentLocation.Text = value;
                checkBoxCustomLocation.Checked = (value == null);
            }
        }


        /// <summary>
        /// Gets or sets a value indicating whether [open in editor].
        /// </summary>
        /// <value><c>true</c> if [open in editor]; otherwise, <c>false</c>.</value>
        public bool OpenInEditor
        {
            get { return radioButtonXmlEditor.Checked; }
            set
            {
                radioButtonXmlEditor.Checked = value;
                radioButtonVisualDesigner.Checked = !value;
            }
        }

        private void checkBoxCustomLocation_CheckedChanged(object sender, EventArgs e)
        {
            textBoxCustomDeploymentLocation.Enabled = browseButton.Enabled = checkBoxCustomLocation.Checked;
            if (!textBoxCustomDeploymentLocation.Enabled)
                textBoxCustomDeploymentLocation.Text = null;
        }

        /// <summary>
        /// Handles the Click event of the browseButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void browseButton_Click(object sender, EventArgs e)
        {
            using (var folderBrowserDialog = new FolderBrowserDialog())
            {
                folderBrowserDialog.RootFolder = Environment.SpecialFolder.MyComputer;
                folderBrowserDialog.ShowNewFolderButton = false;
                folderBrowserDialog.Description = "Choose custom deployment location";
                folderBrowserDialog.SelectedPath = Environment.CurrentDirectory;

                if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                    textBoxCustomDeploymentLocation.Text = folderBrowserDialog.SelectedPath;
            }
        }
    }
}